package com.hanthink.web.controller.app.manhourfact;


import com.hanthink.common.constant.HttpStatus;
import com.hanthink.common.core.controller.BaseController;
import com.hanthink.common.core.page.TableDataInfo;
import com.hanthink.common.core.text.Convert;
import com.hanthink.framework.web.service.TokenService;
import com.hanthink.system.domain.manhour.FactWorkerUsed;
import com.hanthink.system.service.manhour.IFactWorkerUsedService;
import org.apache.velocity.runtime.directive.Foreach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/app/manhourfact/confirmlabor")
public class ConfirmlaborControll extends BaseController {
    @Autowired
    private IFactWorkerUsedService factWorkerUsedService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查詢未审核记录
     */
    @PostMapping("/query")
    public TableDataInfo queryconfirmlabor(@RequestBody Map<String, Object> map) throws ParseException {
        FactWorkerUsed factWorkerUsed= new FactWorkerUsed();
        factWorkerUsed.setCompanyid(map.get("companyid").toString());
        factWorkerUsed.setChecked(Convert.toInt(map.get("checked").toString()));

        List<FactWorkerUsed> list = factWorkerUsedService.selectFactWorkerUsedList(factWorkerUsed);
        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setCode(HttpStatus.SUCCESS);
        tableDataInfo.setMsg("操作成功");
        tableDataInfo.setRows(list);
         return tableDataInfo;
    }
    @PostMapping("/querynotaudititem")
    public TableDataInfo querynotaudititem(@RequestBody Map<String, Object> map) throws ParseException {
        FactWorkerUsed listitem = factWorkerUsedService.selectFactWorkerUsedById(Convert.toLong(map.get("id").toString()));
        List<FactWorkerUsed> list=new ArrayList<FactWorkerUsed>();
        list.add(listitem);
        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setCode(HttpStatus.SUCCESS);
        tableDataInfo.setMsg("操作成功");
        tableDataInfo.setRows(list);
        return tableDataInfo;
    }
    /**
     * 审核未审核记录
     */
    @PostMapping("/audit")
    public TableDataInfo auditconfirmlabor(@RequestBody Map<String, Object> map) throws ParseException {
        FactWorkerUsed factWorkerUsed= new FactWorkerUsed();
        factWorkerUsed.setId(Convert.toLong(map.get("id").toString()));
        factWorkerUsed.setChecked(Convert.toInt(1));
        factWorkerUsed.setChecktor(map.get("checktor").toString());
//        factWorkerUsed.setWorkhour(Convert.toFloat(map.get("workhour").toString()));
        Date date =new Date();
        factWorkerUsed.setCheckdatetime(date);

        int i = factWorkerUsedService.updateFactWorkerUsed(factWorkerUsed);
        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setCode(HttpStatus.SUCCESS);
        tableDataInfo.setMsg("审核成功");
        return tableDataInfo;
    }
}
